package facade

import (
	"fmt"
	"strings"
)

type Order struct {
}

func (o *Order) Create(product ...string) {
	fmt.Println("创建订单，商品为：", strings.Join(product, ","))
}

func (o *Order) Cancel(orderNum string) {
	fmt.Println("取消订单，订单号：", orderNum)
}

type Payment struct {
}

func (p *Payment) Pay() {
	fmt.Println("订单支付")
}

func (p *Payment) Refund() {
	fmt.Println("订单退款")
}

type OrderFacade struct {
	order   *Order
	payment *Payment
}

func (f *OrderFacade) Create(product ...string) {
	f.order.Create(product...)
	f.payment.Pay()
}

func (f *OrderFacade) Cancel(orderNum string) {
	f.order.Cancel(orderNum)
	f.payment.Refund()
}

func NewOrderFacade() *OrderFacade {
	return &OrderFacade{
		order:   &Order{},
		payment: &Payment{},
	}
}
